package com.yt.app.provider.service.impl;

import com.yt.app.core.interfaces.UserOrderDetailService;
import com.yt.app.core.model.UserOrderDetail;
import com.yt.app.provider.dao.UserOrderDetailDao;
import com.yt.core.dao.filter.DynamicSQLFilterImpl;
import com.yt.core.dao.filter.QueryFilter;
import com.yt.core.service.GenericServiceImpl;

import java.util.List;

public class UserOrderDetailServiceImpl extends GenericServiceImpl<UserOrderDetail, Long> implements UserOrderDetailService {
	private UserOrderDetailDao dao;

	public UserOrderDetailServiceImpl() {
	}

	public UserOrderDetailServiceImpl(UserOrderDetailDao dao) {
		super(dao);
		this.dao = dao;
	}

	@Override
	public List<UserOrderDetail> getByOrderId(Long userOrderId) {
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.setPagingBean(null);
		filter.addFilter("Q_userOrderId_L_EQ", String.valueOf(userOrderId));
		filter.setSortField("productId", false);
		return this.dao.find(filter);
	}

	@Override
	public List<UserOrderDetail> getValidDetailListByUid(Long uid, Long lastId, Integer limit) {
		return this.dao.getValidDetailListByUid(uid, lastId, limit);
	}

	@Override
	public UserOrderDetail getByCardNo(String cardNo) {
		return getByCardNoAndPwd(cardNo, null);
	}
		@Override
	public UserOrderDetail getByCardNoAndPwd(String cardNo, String pwd){
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.setPagingBean(null);
		filter.addFilter("Q_cardNo_S_EQ", cardNo);
		if(pwd != null) {
			filter.addFilter("Q_cardPassword_S_EQ", pwd);
		}
		filter.setSortField("productId", false);
		List<UserOrderDetail> list = dao.find(filter);
		if(list != null && !list.isEmpty()){
			return list.get(0);
		}
		return null;
	}
}
